﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NoteList.Delegates;
using NoteList.Models;
using NoteList.EvtArgs;

namespace NoteList.Forms
{
    public partial class NoticeForm : Form
    {
        public event NoteChanged OnNoteChanged;
        public event NodeEventHandler OnNoteEditRequest;
        private ZNote _note = null;

        public NoticeForm()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.Manual;
            Rectangle screenBounds = Screen.PrimaryScreen.Bounds;
            this.SetBounds(screenBounds.Width - this.Bounds.Width - 30,
                screenBounds.Height - this.Bounds.Height - 100, this.Bounds.Width, this.Bounds.Height);
            lbNote.MaximumSize = new Size(this.Bounds.Width - 20, this.Bounds.Height - 40);
        }

        public void ShowNote(ZNote note)
        {
            _note = note;
            RefreshValue();
            btOK.Visible = false;
            btReSet.Visible = false;
            lbNote.Visible = false;

            this.Opacity = 0.1;
            this.Show();
            for (double i = 0.1; i < 1.0; i = i + 0.1)
            {
                this.Opacity = i;
                System.Threading.Thread.Sleep(50);
            }
            btOK.Visible = true;
            btReSet.Visible = true;
            lbNote.Visible = true;
        }

        private void RefreshValue()
        {
            lbNote.Text = "问丽水\r\n你是在哪个同仁堂买的他们给磨粉啊?你是在哪个同仁堂买的他们给磨粉啊你是在哪个同仁堂买的他们给磨粉啊这两天去了家附近的几个药店都不给磨,周围还没有同仁堂,所以想问清楚了省得到";
            if (_note != null)
                lbNote.Text = _note.Title + "\r\n" + _note.Content;
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void lbNote_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (_note != null && OnNoteEditRequest != null)
            {
                NoteEventArgs ne = new NoteEventArgs();
                ne.Note = _note;
                OnNoteEditRequest.Invoke(this, ne);
            }
            this.Close();
        }

        private void btReSet_Click(object sender, EventArgs e)
        {
            if (_note != null && OnNoteChanged != null)
            {
                _note.AlarmTime = DateTime.Now.AddMinutes(5);
                NoteChangeEventArgs ne = new NoteChangeEventArgs();
                ne.Note = _note;
                ne.IsNewNote = false;
                OnNoteChanged.Invoke(this, ne);
            }
            this.Close();
        }
    }
}
